package com.traffic.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.traffic.domain.UserBasicinformation;
import com.traffic.service.IUserBasicinformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 用户基础信息Controller
 *
 * @author zzs
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/information")
public class UserBasicinformationController extends BaseController
{
    @Autowired
    private IUserBasicinformationService userBasicinformationService;

    /**
     * 查询用户基础信息列表
     */
    @RequiresPermissions("information:information:list")
    @GetMapping("/list")
    public TableDataInfo list(UserBasicinformation userBasicinformation)
    {
        startPage();
        List<UserBasicinformation> list = userBasicinformationService.selectUserBasicinformationList(userBasicinformation);
        return getDataTable(list);
    }

    /**
     * 导出用户基础信息列表
     */
    @RequiresPermissions("information:information:export")
    @Log(title = "用户基础信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, UserBasicinformation userBasicinformation)
    {
        List<UserBasicinformation> list = userBasicinformationService.selectUserBasicinformationList(userBasicinformation);
        ExcelUtil<UserBasicinformation> util = new ExcelUtil<UserBasicinformation>(UserBasicinformation.class);
        util.exportExcel(response, list, "用户基础信息数据");
    }

    /**
     * 获取用户基础信息详细信息
     */
    @RequiresPermissions("information:information:query")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(userBasicinformationService.selectUserBasicinformationByUserId(userId));
    }

    /**
     * 新增用户基础信息
     */
    @RequiresPermissions("information:information:add")
    @Log(title = "用户基础信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserBasicinformation userBasicinformation)
    {
        return toAjax(userBasicinformationService.insertUserBasicinformation(userBasicinformation));
    }

    /**
     * 修改用户基础信息
     */
    @RequiresPermissions("information:information:edit")
    @Log(title = "用户基础信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserBasicinformation userBasicinformation)
    {
        return toAjax(userBasicinformationService.updateUserBasicinformation(userBasicinformation));
    }

    /**
     * 删除用户基础信息
     */
    @RequiresPermissions("information:information:remove")
    @Log(title = "用户基础信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(userBasicinformationService.deleteUserBasicinformationByUserIds(userIds));
    }
}
